import Mock from 'mockjs'


let arr = []
import {
  param2Obj
} from "@/utils/myUtils";
for (let i = 0; i < 100; i++) {
  let num = Mock.mock('@integer(0, 2)')
  arr.push({
    id: Mock.mock('@id'),
    name: Mock.mock('@cname'),
    age: Mock.mock('@integer(0, 99)'),
    sex: ['男', '女', ][Mock.mock('@integer(0, 1)')],
    hospitalNum: Mock.mock('@natural(5000000000, 5000900000)'),
    idtype: ['身份证', '临时身份证', '美国护照'][num],
    witeTime: ['现场排号', '网上预约', 'app预约'][num],
    hospital: ['北京市第一人民医院/东院', '昌平沙河医院', '北京骨科医院'][num],
    idNUm: Mock.mock('@id'),
    phone: Mock.mock('@natural(20000000000, 10000000000)'),
    package1: Mock.mock('体检套餐@character("lower")'),
    cost: Mock.Random.integer(1000, 10000),
    state: Mock.mock('@natural(0, 2)'),
    dateaphy: Mock.mock('@datetime'),
    makeTime: Mock.Random.datetime('yyyy-MM-dd  00:00:00'),
    address: Mock.Random.county(true),
    bz: ''
  })
}





export default {
  phyHomeDate: config => {
    // console.log(param2Obj(config.url))
    const {
      state,
      page,
      pageSize,
      time
    } = param2Obj(config.url)

    let res = []
    if (state) {
      res = arr.filter(item => {
        return item.state == state && Date.parse(item.makeTime) == time
      })
    } else {
      res = arr
    }
    // if (time) {
    //   res = arr.filter(item => {
    //     return Date.parse(item.makeTime) == time
    //   })
    // }
    // 分页
    let newarr = res.filter((item, index) => {
      return (page - 1) * pageSize <= index && index < page * pageSize

    })
    return {
      code: 200,
      msg: '请求成功',
      data: newarr,
      total: arr.length
    }
  },

  PhyEditData: config => {
    console.log(JSON.parse(config.body));
    const {
      id,
      name,
      hospitalNum,
      idtype,
      witeTime,
      hospital,
      idNUm,
      package1,
      cost,
      dateaphy,
      makeTime,
      address,
      bz
    } = JSON.parse(config.body)
    arr.forEach(item => {
      if (item.id == id) {
        item.name = name
        item.hospitalNum = hospitalNum
        item.idtype = idtype
        item.witeTime = witeTime
        item.hospital = hospital
        item.idNUm = idNUm
        item.package1 = package1
        item.cost = cost
        item.dateaphy = dateaphy
        item.makeTime = makeTime
        item.address = address
        item.bz = bz
      }
    })
    return {
      code: 200,
      msg: '请求成功',
      data: null
    }
  },

  PhyBodyData: config => {
    return {
      code: 200,
      msg: '请求成功',
      data: [{
          name: '身高',
          end: '175cm',
          refer: ''
        },
        {
          name: '体重',
          end: '65kg',
          refer: '18.5-22.9'
        },
        {
          name: 'BiMI',
          end: '19',
          refer: '90-140'
        },
        {
          name: '血压(收缩压)',
          end: '139mm/Hg',
          refer: '90-140'
        },
        {
          name: '血压(舒张压)',
          end: '70mm/Hg',
          refer: '60-90'
        }
      ]
    }
  },

  PhyBloodData: config => {
    return {
      code: 200,
      msg: '请求成功',
      data: [{
          name: '血红蛋白',
          end: '300g/L',
          refer: '115-150g/L'
        },
        {
          name: '红细胞',
          end: '300g/L',
          refer: '115-150g/L'
        },
        {
          name: '血小板',
          end: '300g/L',
          refer: '115-150g/L'
        },
        {
          name: '单核细胞绝对值',
          end: '300g/L',
          refer: '115-150g/L'
        },
        {
          name: '淋巴细胞绝对值',
          end: '300g/L',
          refer: '115-150g/L'
        },
        {
          name: '淋巴细胞百分比',
          end: '300g/L',
          refer: '115-150g/L'
        },
        {
          name: '平均红细胞体积',
          end: '300g/L',
          refer: '115-150g/L'
        },
      ]
    }
  }
}